/*
 * @lc app=leetcode.cn id=121 lang=cpp
 *
 * [121] 买卖股票的最佳时机
 */
#include "include.h"
// @lc code=start
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int res = 0;

        if (prices.empty()){return 0;}

        int historyMinPrice = prices.front();
        for (auto& price : prices){
            int currentIntrest = price - historyMinPrice;
            if (currentIntrest > res){
                res = currentIntrest;
            }
            if (price < historyMinPrice){
                historyMinPrice = price;
            }
        }

        return res;
    }
};
// @lc code=end

